package com.ttbj.core.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class MarkNumUtil {
	private static long orderNum = 0l;
	private static SimpleDateFormat format = new SimpleDateFormat("yyMMdd");


	public static String create() {
		String[] strings = { "A", "S", "E", "B", "D", "W", "F", "J", "L", "Z" };
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < 5; i++) {
			sb.append(strings[(int) Math.floor(Math.random() * 10)]);
			sb.append((int) Math.floor(Math.random() * 10) + "");
		}
		return sb.toString();
	}

	/**
	 * 生成License
	 * 
	 * @return
	 */
	public static String licenseCreate() {
		String[] strings = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N" };
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < strings.length; i++) {
			sb.append(strings[(int) Math.floor(Math.random() * 10)]);
			sb.append((int) Math.floor(Math.random() * 10) + "");
		}
		return sb.toString();
	}

	/**
	 * 生成单纯数字的公司编号
	 * @return
	 */
	private static synchronized String getOrderNo(String date, Long time) {
		String str = format.format(new Date(time)); // 当前的日期
		if (date == null || !date.equals(str)) { // 如果日期和当天日期生成的订单号不一样
			date = str;
			orderNum = 0l;
		}
		++orderNum;
		long orderNo = Long.parseLong((date)) * 1000000;
		orderNo += orderNum;
		return orderNo + "";
	}

	/**
	 * 生成包含有字母的公司编号
	 * @param pexStr	前置 
	 * @return
	 */
	public static synchronized String getNo(String pexStr) {
		long time = System.currentTimeMillis();
		String split = time + "";
		split = split.substring(9, 13);
		String date = format.format(new Date(time));
		String orderNo = getOrderNo(date, time);
		return pexStr + split + orderNo;
	}

}
